package sam.classe;

import java.io.IOException;
import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Connection extends Activity implements View.OnClickListener {

	private static final String FLAG_SUCCESS = "success";
	private static final String FLAG_MESSAGE = "message";
	
	private Button connecter;
	private Button inscription;
	private EditText login;
	private EditText mdp;
	private static Connection connection;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.connection);
		
		connecter = (Button)findViewById(R.id.connection);
		inscription = (Button)findViewById(R.id.inscrire);
		login = (EditText)findViewById(R.id.pseudo);
		mdp = (EditText)findViewById(R.id.password);
		
		connection = this;
		
		connecter.setOnClickListener(this);
		inscription.setOnClickListener(this);
	}
	
	public void onClick(View v) {
		
		switch(v.getId()){
			case R.id.connection:
				String usernameTxt = login.getText().toString();
				String passwordTxt = mdp.getText().toString();
				
				ConnectDb cdb = new ConnectDb();
				cdb.execute(usernameTxt, passwordTxt);
			break;
			
			case R.id.inscrire:
				Intent inscri = new Intent(Connection.this, User.class);
				startActivity(inscri);
			break;
		}
	}
	
	public static void verif(String reponse)
	{
		if(reponse.equals("true"))
		{
			Intent vue = new Intent(connection, VueSoiree.class);
			connection.startActivity(vue);
		}
		else if(reponse.equals("false"))
		{
		}
	}
}
